package com.warm.orm.mp.sys.agent;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.warm.core.page.TableDataInfo;
import com.warm.orm.domain.sys.SysHotPlug;
import com.warm.orm.domain.sys.dto.SysHotPlugDto;
import com.warm.orm.domain.sys.vo.SysHotPlugVo;
import com.warm.orm.mp.sys.mapper.SysHotPlugMapper;
import com.warm.orm.utils.PageUtils;
import com.warm.system.api.orm.agent.SysHotPlugAgent;
import org.apache.ibatis.solon.annotation.Db;
import org.noear.solon.annotation.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static com.warm.orm.domain.sys.convert.SysHotPlugC.sysHotPlugC;

@Component
public class SysHotPlugAgentImpl  implements SysHotPlugAgent {
    @Db
    SysHotPlugMapper sysHotPlugMapper;

    @Override
    public SysHotPlugVo selectById(String qualifiedName) {
        SysHotPlug sysHotPlug = sysHotPlugMapper.selectById(qualifiedName);
        return sysHotPlugC.convert(sysHotPlug);

    }

    @Override
    public TableDataInfo<SysHotPlugVo> selectPage(SysHotPlugDto dto) {
        PageUtils.startPage();
        List<SysHotPlugVo> page = this.selectList(dto);
        return PageUtils.getDataTable(page);
    }

    @Override
    public List<SysHotPlugVo> selectList(SysHotPlugDto dto) {
        List<SysHotPlug> page = sysHotPlugMapper.selectHotPlugList(dto);
        if (CollUtil.isNotEmpty(page) ) {
            return page.stream().map(sysHotPlugC::convert)
                    .collect(Collectors.toList());
        }
        return  new ArrayList<>();
    }

    @Override
    public int insertByDto(SysHotPlugDto dto) {
        return sysHotPlugMapper.insert(sysHotPlugC.convert(dto));
    }

    @Override
    public int updateByDto(SysHotPlugDto dto) {
        return sysHotPlugMapper.updateById(sysHotPlugC.convert(dto));
    }

    @Override
    public int deleteByIds(String[] qualifiedNames) {
        if(ObjectUtil.isEmpty(qualifiedNames)){
            return 0;
        }
        List<String> qualifiedNameList = Arrays.asList(qualifiedNames);
        return sysHotPlugMapper.deleteBatchIds(qualifiedNameList);
    }

    @Override
    public boolean checkDictTypeUnique(SysHotPlugDto dto) {
        return false;
    }
}
